/**
 * Created by liuqingling on 16/1/27.
 */

define(['backbone'], function(Backbone) {
    var items = [{
        id: '0',
        isselect:true,
        title:'财务会计'
    }];

    var Model = Backbone.Model.extend({
        defaults: function() {
            return {
                id: '0',
                isselect:true,
                title:'财务会计'
            };
        },
        destroy:function(){
            this.trigger('destroy');
        }
    });


    var collections = Backbone.Collection.extend({
        model: Model,
        url: "./api/showcase",
        state: {},
        id:'',
        fetch: function() {
            this.addItem();
        },
        setmode:function(m){
            this.mode=m;
        },
        setid:function(id){
            this.id=id;
        },
        addData:function(datas){
                this.reset();
                this.reset(datas);
                // if (datas instanceof Array) {
                //     for (var i = 0; i < datas.length; i++) {
                //         this.add(new Model(datas[i]));
                //     }
                // }
        },
        addItem: function(){
            // for (var i = 0; i < this.pageSize; i++) {
            //     var position = this.curPageIndex * this.pageSize + i;
            //     if(items.length > position){
            //         //this.add(new Model(items[position]));
            //     }else{
            //         break;
            //     }
            // }
        },
        curPageIndex: 0,
        pageSize: 10,
        getNextPage: function() {
            this.curPageIndex += 1;
            this.addItem();
        },
        hasNextPage: function() {
            // return items.length/ this.pageSize > this.curPageIndex;
        },
        getFirstPage: function() {
            this.curPageIndex = 0;
            this.addItem();
        },
    });

    return collections;
});
